﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CopsBanditsUI {
    import flash.events.*;
    import Events.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Modules.workers.*;
    import Display.ValentineUI.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;
    import Display.CopsBanditsUI.OfficerCellStates.*;

    public class OfficerCell extends CrewCell {

        public static const STATE_READY:String = "state_ready";
        public static const STATE_PATROLLING:String = "state_patrolling";
        public static const STATE_SLEEPING:String = "state_sleeping";
        public static const STATE_EMPTY:String = "state_empty";
        public static const STATE_LOCKED:String = "state_locked";

        protected var m_gridList:GridList;
        protected var m_index:int;
        protected var m_officer:CopData;
        protected var m_color:int;
        protected var m_officerState:String;

        public function OfficerCell(_arg1:OfficerCellFactory, _arg2:int, _arg3:LayoutManager=null){
            this.m_color = _arg2;
            super(_arg1, _arg3);
        }
        override public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
            if (_arg1){
                this.m_gridList = _arg1;
                this.m_index = _arg3;
                _arg1.setTileWidth(595);
                _arg1.setTileHeight(55);
            };
        }
        override public function buildCell():void{
            this.removeAll();
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            switch (this.m_officerState){
                case STATE_PATROLLING:
                    _local1.append(new OnDutyOfficerState(this.m_officer, this.m_color, this));
                    break;
                case STATE_READY:
                    _local1.append(new ReadyOfficerState(this.m_officer, this.m_color, this));
                    break;
                case STATE_SLEEPING:
                    _local1.append(new SleepingOfficerState(this.m_officer, this.m_color, this));
                    break;
                case STATE_EMPTY:
                    _local1.append(new EmptyOfficerState(this.m_color, this));
                    break;
                case STATE_LOCKED:
                    _local1.append(new LockedOfficerState(this.m_color, this));
                    break;
            };
            this.append(_local1);
        }
        override public function setCellValue(_arg1):void{
            if (_arg1 == "empty"){
                this.m_officerState = STATE_EMPTY;
            } else {
                if (_arg1 == "locked"){
                    this.m_officerState = STATE_LOCKED;
                } else {
                    this.m_officer = _arg1;
                    this.m_officerState = this.m_officer.getState();
                };
            };
            if (!this.hasEventListener(UIEvent.CHANGE_CREW_STATE)){
                this.addEventListener(UIEvent.CHANGE_CREW_STATE, this.rebuildCell, false, 0, true);
            };
            this.buildCell();
            ASwingHelper.prepare(this);
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        public function forceRebuildCell(_arg1:String, _arg2:Boolean=false, _arg3:Boolean=false):void{
            this.m_officerState = _arg1;
            if (_arg2){
                this.m_officer.setState(CopData.STATE_PATROLLING);
            };
            if (_arg3){
                this.m_officer.setTimestamp(Math.floor((GlobalEngine.getTimer() / 1000)));
            };
            this.buildCell();
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        protected function rebuildCell(_arg1:UIEvent):void{
            var _local5:CopData;
            this.m_officerState = _arg1.label;
            var _local2:CopsNBanditsWorkers = (Global.copsNBanditsWorkerManager.getWorkers("cops") as CopsNBanditsWorkers);
            var _local3:Array = _local2.getAllCopData();
            var _local4:int;
            while (_local4 < _local3.length) {
                _local5 = _local3[_local4];
                if (_local5.getPosition() == this.m_officer.getPosition()){
                    this.m_officer = _local5;
                };
                _local4++;
            };
            this.buildCell();
            ASwingHelper.prepare(this);
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        override public function getCellComponent():Component{
            return (this);
        }

    }
}//package Display.CopsBanditsUI 
